package edu.xidian.bdilab.jrbigdata.controller.admin;
import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.domain.GovernmentInfo;
import edu.xidian.bdilab.jrbigdata.service.admin.governmentadmin.governmentadminService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/admin/governmentManage")
@Api(tags = {"政府信息管理"})
public class GovernmentManageController {
    @Autowired
    governmentadminService governmentadminService;

    @ResponseBody
    @ApiOperation("查看政府联系人")
    @RequestMapping(value = "/check", method = RequestMethod.POST)
    public ResponseResult bankManage_check(@RequestParam(required = false) @ApiParam(value = "企业用户名") String userName,
                                           @RequestParam(required = false) @ApiParam(value = "政府代码") String governmentCode,
                                           @RequestParam(required = false) @ApiParam(value = "部门") String departmentName,
                                           @RequestParam(required = false) @ApiParam(value = "负责人姓名") String principalName,
                                           @RequestParam(required = false) @ApiParam(value = "负责人电话") String principalPhone)throws Exception
    {
        GovernmentInfo governmentInfo=new GovernmentInfo();
        governmentInfo.setFkUserName(userName);
        governmentInfo.setDepartmentName(departmentName);
        governmentInfo.setPrincipalName(principalName);
        governmentInfo.setPrincipalPhone(principalPhone);
        if(governmentCode==null||governmentCode.length()==0){
        governmentInfo.setGovernmentCode(0);
        }
        ResponseResult responseResult=governmentadminService.governmentManage_check(governmentInfo);
        return responseResult;
    }

    @ResponseBody
    @ApiOperation("新增政府联系人")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResponseResult  bankManage_add(@RequestParam @ApiParam(value = "企业用户名",required = true) String userName,
                                          @RequestParam @ApiParam(value = "企业密码",required = true) String password,
                                          @RequestParam @ApiParam(value = "政府代码",required = true) Integer governmentCode,
                                          @RequestParam @ApiParam(value = "部门",required = true) String departmentName,
                                          @RequestParam @ApiParam(value = "负责人姓名",required = true) String principalName,
                                          @RequestParam @ApiParam(value = "负责人电话",required = true) String principalPhone)throws Exception
    {
        GovernmentInfo governmentInfo=new GovernmentInfo();
        governmentInfo.setFkUserName(userName);
        governmentInfo.setDepartmentName(departmentName);
        governmentInfo.setPrincipalName(principalName);
        governmentInfo.setPrincipalPhone(principalPhone);
        governmentInfo.setGovernmentCode(governmentCode);
        ResponseResult responseResult=governmentadminService.governmentManage_add(governmentInfo,password);
        return responseResult;
    }

    @ResponseBody
    @ApiOperation("编辑政府联系人")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseResult  bankManage_update(@RequestParam @ApiParam(value = "企业用户名",required = true) String userName,
                                             @RequestParam @ApiParam(value = "企业密码",required = true) String password,
                                             @RequestParam @ApiParam(value = "政府代码",required = true) Integer governmentCode,
                                          @RequestParam @ApiParam(value = "部门",required = true) String departmentName,
                                          @RequestParam @ApiParam(value = "负责人姓名",required = true) String principalName,
                                          @RequestParam @ApiParam(value = "负责人电话",required = true) String principalPhone)throws Exception
    {
        GovernmentInfo governmentInfo=new GovernmentInfo();
        governmentInfo.setFkUserName(userName);
        governmentInfo.setDepartmentName(departmentName);
        governmentInfo.setPrincipalName(principalName);
        governmentInfo.setPrincipalPhone(principalPhone);
        governmentInfo.setGovernmentCode(governmentCode);
        ResponseResult responseResult=governmentadminService.governmentManage_update(governmentInfo,password);
        return responseResult;
    }

    @ResponseBody
    @ApiOperation("删除政府联系人")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResponseResult  bankManage_delete(@RequestParam @ApiParam(value = "企业用户名") String userName)throws Exception
    {

        ResponseResult responseResult=governmentadminService.governmentManage_delete(userName);
        return responseResult;
    }
}
